﻿using System;
using System.Data;
using System.IO;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建表
            DataTable dt = new DataTable();

            //1、添加列
            dt.Columns.Add("UserName", typeof(string)); //数据类型为 文本
            //2、通过列架构添加列
            DataColumn age = new DataColumn("Age", typeof(Int32));   //数据类型为 整形
            DataColumn Time = new DataColumn("AddTime", typeof(DateTime)); //数据类型为 时间
            dt.Columns.Add(age);
            dt.Columns.Add(Time);

            for (int i = 0; i <= 1048776; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = "张三" + i.ToString(); //通过索引赋值
                dr[1] = 23;
                dr["AddTime"] = DateTime.Now;//通过名称赋值
                dt.Rows.Add(dr);
            }

            var bytes = DoNet.Utils.NpoiUtil.ExportDataTableToExcel(dt, "人员表");

            //string[,,] column_FieldTextWidth = new[, ,]{
            //    {  {"UserName", "姓名", "80"} },
            //    {  {"AddTime", "时间", "120"} },
            //};
            //var bytes = DoNet.Utils.NpoiUtil.ExportDataTableToExcel(dt, "人员表", true, column_FieldTextWidth);

            using (FileStream writefile = new FileStream("output.xlsx", FileMode.OpenOrCreate, FileAccess.Write))
            {
                writefile.Write(bytes, 0, bytes.Length);
            }
            // 再次写入一些文本到控制台，它将显示在控制台上
            Console.WriteLine("这是输出到控制台的文本");
        }
    }
}
